package at.fhj.itm10.ticketmaster.helper;

import javax.annotation.Resource;
import javax.mail.Session;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 * gets mail session configuration
 * 
 * @author stefan leisenberger
 */

public class MailHelper {
	
	@Resource(name = "TicketmasterMail", type = Session.class)
	private Session session;
	
	private static MailHelper instance;

	/**
	 * Gets the mail session.
	 * @throws Exception 
	 * 
	 * @see http://tomee.apache.org/configuring-javamail.html
	 */
	private MailHelper() throws Exception {
//		new ResourceXmlChecker();
		
		if (session == null) {
			Context ctx = new InitialContext();
			session = (Session) ctx
					.lookup("java:comp/env/TicketmasterMail");
		}
		
		if (session == null) {
			throw new NullPointerException("session is null");
		}
	}

	public static Session getSession() throws Exception {
		if (instance == null) {
			instance = new MailHelper();
		}
		return instance.session;
	}
	
}
